//
//  ViewController.swift
//  1-08-字典
//
//  Created by 范英强 on 16/1/23.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        demo2()
    }
    
    //字典的合并
    func demo2(){
        var dict1 = ["name":"老王","age":18]
        let dict2 = ["title":"哈哈"]
        
        for (key, value) in dict2 {
            dict1[key] = value
        }
        
        print(dict1)
        
        //删除
        
//        dict1.removeValueForKey("name")
        dict1["name"] = nil
        
    }
    //定义字典
    func demo1(){
        let dict1 = ["name":"老王","age":18]
        print(dict1)
        print("==============")
        
        //初始化字典
        var dict2:[String : NSObject] = [String : NSObject]()
        //给字典添加键值对
        dict2["name"] = "老张"
        dict2["age"] = 18
        print(dict2)
        //添加键值对的时候如果 key存在 那就替换value 不存在的话 创建一个键值对
        dict2["name"] = "老赵"
        
        
    }


}

